package com.nickstumpos.android.GmailWidgetPlus.widget.presentation.managers.displaylabels.twobytwo.skins;

import java.util.List;

import android.content.Context;
import android.util.Log;

import com.nickstumpos.android.GmailWidgetPlus.R;
import com.nickstumpos.android.GmailWidgetPlus.widget.presentation.managers.SimpleLabel;
import com.nickstumpos.android.GmailWidgetPlus.widget.presentation.managers.WidgetUIData;
import com.nickstumpos.android.GmailWidgetPlus.widget.presentation.managers.displaylabels.twobytwo.TwoByTwoWidgetUIManager;
import com.nickstumpos.android.GmailWidgetPlus.widget.sizes.WidgetSize;
import com.nickstumpos.android.GmailWidgetPlus.widget.skins.WidgetSkins;

public class TwoByTwoClassicManager extends TwoByTwoWidgetUIManager {

	public static TwoByTwoClassicManager create(final Context context,
			final int widgetId,
			final WidgetSkins type,
			final String account,
			final WidgetSize size) {

		return new TwoByTwoClassicManager(context,
				widgetId,
				type,
				account,
				size);
	}

	private final List<SimpleLabel>	labelViewData	= null;

	private TwoByTwoClassicManager(final Context context,
			final int widgetId,
			final WidgetSkins type,
			final String account,
			final WidgetSize size) {

		super(context, new WidgetUIData(widgetId,
				type,
				account,
				size,
				R.id.UpButton,
				R.id.DownButton,
				R.id.DownButton_disabled,
				R.id.UpButton_disabled,
				R.id.UnreadButton,
				R.id.NoUnreadMailText,
				R.id.NoUnreadMail));
	}

	@Override
	public List<SimpleLabel> getLabelViewData() {
		if (this.labelViewData == null) {
			this.initLabelViewData();
		}
		return this.labelViewData;
	}

	@Override
	protected WidgetSize getSize() {
		return WidgetSize.TWOxTWO;
	}

	@Override
	protected WidgetSkins getWidgetSkin() {
		return WidgetSkins.TWO_BY_TWO_CLASSIC;
	}

	protected void initLabelViewData() {

		this.getLabelViewData().add(new SimpleLabel(R.id.Label0,
				0,
				R.id.hr0,
				R.id.labelOne,
				R.id.Count0));
		this.getLabelViewData().add(new SimpleLabel(R.id.Label1,
				1,
				R.id.hr1,
				R.id.labelTwo,
				R.id.Count1));
		this.getLabelViewData().add(new SimpleLabel(R.id.Label2,
				2,
				R.id.hr2,
				R.id.labelThree,
				R.id.Count2));
		this.getLabelViewData().add(new SimpleLabel(R.id.Label3,
				3,
				R.id.hr3,
				R.id.labelFour,
				R.id.Count3));
		this.getLabelViewData().add(new SimpleLabel(R.id.Label4,
				4,
				R.id.hr4,
				R.id.labelFive,
				R.id.Count4));
	}

	@Override
	protected int labelIncrementAmount() {
		return 1;
	}

	@Override
	protected void loadChange() {
		Log.i("GMWP", "Changing state of widget: " + this.getWidgetId());
		if (!this.isHaveAccount()) {
			this.changeToStateNoAccount();
		} else {
			if (this.getLabels().size() == 0) {
				this.changeToStateNoUnread();
			} else {
				this.changeToStateIsUnread();
			}
			this.setArrowButtonStates();
		}
		this.commitUpdate();
	}
}
